package com.example.movie.Service;

import com.example.movie.Entity.Movie;
import com.example.movie.Repository.MovieMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MovieService {
    private final MovieMapper movieMapper;

    public MovieService(MovieMapper movieMapper) {
        this.movieMapper = movieMapper;
    }

    public List<Movie> getAllMovies() {
        // System.out.println("Query result: " + movieMapper.findAll());
        return movieMapper.findAll();
    }

    public Map<String, List<String>> getFilterOptions() {
        Map<String, List<String>> options = new HashMap<>();
        options.put("regions", movieMapper.findDistinctRegions());
        options.put("genres", movieMapper.findDistinctGenres());
        options.put("years", movieMapper.findDistinctYears());
        return options;
    }

    public List<Movie> getFilteredMovies(String title,String region, String genre, Integer year) {
        return movieMapper.findFilteredMovies(title,region, genre, year);
    }
}